---
category: Math
created: '2021-04-05'
title: Calculate the distance between two points
updated: '2021-10-13'
---

**JavaScript version**

```js distance.js
const distance = (p1, p2) => Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
```

**TypeScript version**

```js distance.ts
interface Point {
    x: number;
    y: number;
}

const distance = (p1: Point, p2: Point): number => Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
```
